﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace JobManager
{
    public class JobScope: IDisposable
    {
        Mutex _mutex;

        public JobScope(string aUserID, string aJobID)
        {
            string lmutexName = "Global\\" + aUserID + ":" + aJobID;

            _mutex = new Mutex(false, lmutexName);

            _mutex.WaitOne();
        }

        #region IDisposable Members

        public void Dispose()
        {
            if (_mutex != null)
            {
                _mutex.ReleaseMutex();
                _mutex.Close();
                _mutex = null;
            }
        }

        #endregion
    }
}
